<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title>油品信息</title>
	<meta http-equiv="Content-type" content="textml; charset=utf-8" />
	<meta content="telephone=no" name="format-detection" />
	<meta name="x5-orientation" content="portrait">
	<meta name="screen-orientation" content="portrait">
	<meta name="viewport"
		content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=yes">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="icon" href="data:;base64,=">
	<link rel="stylesheet" type="text/css" href="//img.ejiayou.com/activity/pages/ejiayoupay/ejiayou/css/reset.css" />
	<link rel="stylesheet" href="css/index.css" />
	<link rel="stylesheet" type="text/css" href="css/index_style.css" />
	<style type="text/css">
		.van-checkbox--horizontal {
			margin-right: 0;
			margin-left: 0.2rem;
		}

		.van-checkbox--horizontal:first-child {
			margin-left: 0;
		}

		.van-checkbox__icon .van-icon {
			width: 100%;
			height: 100%;
		}

		.station_info_item label {
			position: absolute;
			right: 0.5rem;
			top: 0;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="load_end" v-if="!loadEnd"></div>
		<div class="tab_content">
			<div class="tab_item tab_active">
				<span>审核信息</span>
			</div>
			<div class="tab_item" @click="comeToExtraMsg">
				<span>补充信息</span>
			</div>
		</div>
		<div class="step_box">
			<img src="https://img.ejiayou.com/activity/jiguang_upload/img/step_active_two.png">
		</div>
		<div class="main_active">
			<van-form @submit="saveComeToNext">
				<van-cell value="油站油品信息"></van-cell>
				<van-field name="radio" label="合作油品">
					<template #input>
						<van-checkbox-group v-model="cooperate_oil" direction="horizontal"
							:rules="[{ required: true, message: '*必须选择一类油品' }]" :disabled="look_gd?true:false">
							<van-checkbox name="92#" checked-color="#FFA400">92#</van-checkbox>
							<van-checkbox name="95#" checked-color="#FFA400">95#</van-checkbox>
							<van-checkbox name="98#" checked-color="#FFA400">98#</van-checkbox>
							<!-- <van-checkbox name="93#" checked-color="#FFA400">93#</van-checkbox>
                        <van-checkbox name="97#" checked-color="#FFA400">97#</van-checkbox> -->
							<van-checkbox name="0#" checked-color="#FFA400">0#</van-checkbox>
						</van-checkbox-group>
					</template>
				</van-field>
				<div class="oil_box" style="min-height: 10rem;">
					<div class="oil_item" v-for="(oil_item, oil_index) in oilInfo">
						<van-cell :value="oil_item.name"></van-cell>
						<div class="station_info_item">
							<van-field v-model="oil_item.countryPrice" name="国家价" label="国家价" placeholder="国家价"
								:rules="[{ required: true, message: '*请填写国家价' }]" readonly></van-field>
							<label>元/升</label>
						</div>
						<div class="station_info_item">
							<van-field v-model="oil_item.oilDiscount" type="number" maxlength=4 name="油机直降" label="油机直降"
								placeholder="油机直降" :rules="[{ validator: validator, message: '请输入油机直降' }]"
								:readonly="look_gd?true: false"></van-field>
							<label>元/升</label>
						</div>
						<div class="station_info_item">
							<van-field v-model="oil_item.stationPrice" name="油站价" label="油站价" placeholder="油站价"
								:rules="[{ validator: validator, message: '请输入正确内容' }]" readonly></van-field>
							<label>元/升</label>
						</div>

						<!-- <div class="station_info_item">
                        <van-field v-model="oil_item.settlePrice" name="结算价" label="结算价" placeholder="结算价" :rules="[{ required: true, message: '*请填写结算价' }]" :readonly="look_gd?true: false"></van-field>
                        <label>元/升</label>
                    </div> -->
						<van-field @click="selectOilGun(oil_item)" readonly clickable v-model="oil_item.oilgunCode"
							name="油枪号" label="油枪号" right-icon="arrow"
							:rules="[{ required: true, message: '*请选择至少一个油枪号' }]"></van-field>
					</div>
				</div>
				<div class="submit_box_step">
					<van-button square type="primary" native-type="button" @click="rebackToLast">上一步</van-button>
					<van-button square type="primary" v-if="!look_gd" native-type="submit">保存并下一步</van-button>
					<van-button square type="primary" v-if="look_gd" native-type="button" @click="lookNextStep">查看下一步
					</van-button>
				</div>
				<div class="submit_box" v-if="from_page">
					<van-button type="primary" @click="rebackPc">关闭页面</van-button>
				</div>
			</van-form>
		</div>
	</div>
	<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	<script src="https://img.ejiayou.com/activity/js/common/jquery.min.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="js/vant.min.js"></script>
	<script src="js/utils.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/area.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		eval(function (p, a, c, k, e, r) {
			e = function (c) {
				return c.toString(a)
			};
			if (!''.replace(/^/, String)) {
				while (c--) r[e(c)] = k[c] || e(c);
				k = [function (e) {
					return r[e]
				}];
				e = function () {
					return '\\w+'
				};
				c = 1
			};
			while (c--)
				if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]);
			return p
		}('(6(a,d){j b=a.i,e="3"f 5?"3":"9",c=6(){b.7.8=(2>b.4?b.4:2)/2*g+"h"};a.0&&(d.0(e,c,!1),a.0("k",c,!1))})(l,5);',
			22, 22,
			'addEventListener||750|orientationchange|clientWidth|window|function|style|fontSize|resize||||||in|64|px|documentElement|var|DOMContentLoaded|document'
				.split('|'), 0, {}))
	</script>
	<script>
		Number.prototype.toFixed = function (len) {
			var add = 0;
			var s = this + "", temp;
			var start = s.indexOf(".");
			if (start > 0) {
				var s1 = s.substr(start + len + 1, 1);
				var s2 = s.substr(0, start + len + 1);
				if (s1 != "") {
					if (s1 >= 5) {
						add = 1;
					}
					s2 = s2.replace(".", "");
					s2 = (Number(s2) >= 0 ? Number(s2) + add : Number(s2) - add);
					s = s2 / Math.pow(10, len);
				}
			}
			return Number(s);
		};

		var json_list = ''

		var admin_id = getQueryVariable('admin_id') || ''
		var work_order_id = getQueryVariable('work_order_id') || ''
		var order_type_id = getQueryVariable('order_type_id') || 1
		var look_gd = getQueryVariable('look_gd') || ''
		var look_gd_text = getQueryVariable('look_gd_text') || ''
		var from_page = getQueryVariable('from_page') || ''
		localStorage.removeItem('ejy_work_order_id') || ''
		// 在 #app 标签下渲染一个按钮组件
		new Vue({
			el: '#app',
			data: {
				activityHost: (window.location.origin.indexOf("dev.ejiayou.com") != -1 ? window.location.origin : "//finance.ejiayou.com"),
				activeIcon: 'https://img.ejiayou.com/activity/jiguang_upload/img/active_icon.png',
				inactiveIcon: 'https://img.ejiayou.com/activity/jiguang_upload/img/inactive_icon.png',
				oilInfo: [],
				loadEnd: false,
				cooperate_oil: [],
				look_gd: look_gd,
				work_order_id: work_order_id,
				order_type_id: order_type_id,
				admin_id: admin_id,
				competitor: '',
				contry_price_list: [],
				look_gd_text: look_gd_text,
				title: '',
				from_page: from_page
			},
			watch: {
				cooperate_oil: {
					handler: function () {
						this.oilInfo = this.initCooperateOils(this.cooperate_oil)
					}
				},
				oilInfo: {

					handler: function (newVal, oldval) {
						let self = this;
						var item_price = 1
						newVal.map(item => {
							item.stationPrice = (Number(item.countryPrice) - (Number(item.oilDiscount) || 0)).toFixed(2)
							item.oilPrice = Number(item.countryPrice) - (Number(item.oilDiscount) || 0)
							if (!item.countryPrice) {
								item_price = 0
							}
						})
						if (item_price == 1) {
							localStorage.setItem('ejy_oilInfo', JSON.stringify(self.oilInfo))
						}

					},
					deep: true
				},
			},
			created() {
				vant.Toast.setDefaultOptions({ duration: 3000 });

			},
			mounted() {
				var self = this
				var cooperate_oil = []
				this.getFormData(function () {
					self.getCountryPrice(json_list.provinceId, json_list.cityId)
					if (json_list && json_list.oilInfo) {

						for (var i = 0; i < json_list.oilInfo.length; i++) {
							cooperate_oil.push(json_list.oilInfo[i].name)
						}
						self.cooperate_oil = cooperate_oil
						if (!self.look_gd) {
							self.competitor = ''
						}
					}
					if (localStorage.getItem('ejy_cooperate_oil')) {
						self.cooperate_oil = JSON.parse(localStorage.getItem('ejy_cooperate_oil'))
					} else {
						if (cooperate_oil.length > 0) {
							self.cooperate_oil = cooperate_oil
						} else {
							self.cooperate_oil = ['92#', '95#']
						}

					}
					self.loadEnd = true
					self.$forceUpdate()
				})
			},
			methods: {
				validator: function (val) {
					return /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/.test(val);
				},
				rebackPc: function () {
					history.back()
				},
				getFormData: function (fn) {
					var self = this
					var data = {
						admin_id: this.admin_id,
						work_order_id: this.work_order_id
					}
					$.ajax({
						url: '/eapi/v1/activity/work/info?t=' + new Date().getTime(),
						data: data,

						type: 'get',
						dataType: 'json',
						success: function (res) {
							console.log(res)
							if (res.status == 200) {
								var resData = res.data
								self.title = resData.title
								json_list = JSON.parse(resData.content)
								if (fn) {
									fn()
								}
							}
						}
					})

				},
				getCountryPrice: function (provinceId, cityId, fn) {
					var self = this
					$.ajax({
						url: this.activityHost + '/cwxt/v3/config/station/countryPrice?provinceId=' + provinceId + '&cityId=' + cityId,
						type: 'get',
						dataType: 'json',
						success: function (res) {
							console.log(res)
							if (res.success == true) {
								var resData = res.data
								if (resData.length == 0) {
									self.cooperate_oil = []
									vant.Toast('您好，当前城市未配置国家价，请联系运营配置国家价')
								}
								// json_list = JSON.parse(resData.content)
								console.log(resData)
								self.contry_price_list = resData
								self.oilInfo = self.initCooperateOils(self.cooperate_oil)
							}
						}
					})
				},
				comeToExtraMsg: function () {
					var self = this
					location.replace('extra_message.html?look_gd_text=' + this.look_gd_text + '&look_gd=' + this.look_gd +
						'&work_order_id=' + self.work_order_id + '&from_page=' + self.from_page + '&admin_id=' + self.admin_id + '&order_type_id=' + self.order_type_id +
						'&reback_url=' + encodeURIComponent(location.href))
				},

				initCooperateOils: function (limit_oils) {
					var limit_oils_list_data = localStorage.getItem('ejy_oilInfo')
					var limit_oils_list = []
					for (var j = 0; j < limit_oils.length; j++) {
						if (limit_oils[j] == '92#') {
							var has_oil_code_1 = 0
							if (JSON.parse(limit_oils_list_data) && JSON.parse(limit_oils_list_data).length > 0) {
								for (var n = 0; n < JSON.parse(limit_oils_list_data).length; n++) {
									if (JSON.parse(limit_oils_list_data)[n].oilId == 1) {
										limit_oils_list.push(JSON.parse(limit_oils_list_data)[n])
										has_oil_code_1 = 1
									}
								}

							} else if (json_list.oilInfo && json_list.oilInfo.length > 0 && json_list.oilInfo[j] && json_list.oilInfo[j]
								.oilId == 1) {
								for (var m = 0; m < json_list.oilInfo.length; m++) {
									if (json_list.oilInfo[m].oilId == 1) {
										limit_oils_list.push(json_list.oilInfo[m])
										has_oil_code_1 = 1
									}
								}

							}
							if (has_oil_code_1 == 0) {
								var countryPrice = ''
								if (this.contry_price_list && this.contry_price_list.length > 0) {
									for (var price of this.contry_price_list) {
										if (price.oil_id == 1) {
											countryPrice = price.oil_price
										}
									}
									if (countryPrice == '') {
										for (var i = 0; i < this.cooperate_oil.length; i++) {
											if (this.cooperate_oil[i] == '92#') {
												this.cooperate_oil.splice(i, 1)
											}
										}
										vant.Toast('92#油品本地没有配置国家价，请联系运营进行配置')
										return
									}
									limit_oils_list.push({
										name: '92#',
										countryPrice: countryPrice,
										stationprice: '',
										oilPrice: '',
										oilDiscount: '',
										settlePrice: '',
										oilgunCode: '',
										oilId: 1
									})
								}
							}

						}
						if (limit_oils[j] == '95#') {
							var has_oil_code_2 = 0
							if (JSON.parse(limit_oils_list_data) && JSON.parse(limit_oils_list_data).length > 0) {
								for (var n = 0; n < JSON.parse(limit_oils_list_data).length; n++) {
									if (JSON.parse(limit_oils_list_data)[n].oilId == 2) {
										limit_oils_list.push(JSON.parse(limit_oils_list_data)[n])
										has_oil_code_2 = 1
									}
								}

							} else if (json_list.oilInfo && json_list.oilInfo.length > 0) {
								for (var m = 0; m < json_list.oilInfo.length; m++) {
									if (json_list.oilInfo[m].oilId == 2) {
										limit_oils_list.push(json_list.oilInfo[m])
										has_oil_code_2 = 1
									}
								}

							}
							if (has_oil_code_2 == 0) {
								var countryPrice = ''
								if (this.contry_price_list && this.contry_price_list.length > 0) {
									for (var price of this.contry_price_list) {
										if (price.oil_id == 2) {
											countryPrice = price.oil_price
										}
									}
									if (countryPrice == '') {
										for (var i = 0; i < this.cooperate_oil.length; i++) {
											if (this.cooperate_oil[i] == '95#') {
												this.cooperate_oil.splice(i, 1)
											}
										}
										vant.Toast('95#油品本地没有配置国家价，请联系运营进行配置')
										return
									}
									limit_oils_list.push({
										name: '95#',
										countryPrice: countryPrice,
										stationprice: '',
										oilPrice: '',
										settlePrice: '',
										oilDiscount: '',
										oilgunCode: '',
										oilId: 2
									})
								}


							}
						}
						if (limit_oils[j] == '0#') {
							var has_oil_code_3 = 0
							if (JSON.parse(limit_oils_list_data) && JSON.parse(limit_oils_list_data).length > 0) {
								for (var n = 0; n < JSON.parse(limit_oils_list_data).length; n++) {
									if (JSON.parse(limit_oils_list_data)[n].oilId == 3) {
										has_oil_code_3 = 1
										limit_oils_list.push(JSON.parse(limit_oils_list_data)[n])
									}
								}

							} else if (json_list.oilInfo && json_list.oilInfo.length > 0) {
								for (var m = 0; m < json_list.oilInfo.length; m++) {
									if (json_list.oilInfo[m].oilId == 3) {
										has_oil_code_3 = 1
										limit_oils_list.push(json_list.oilInfo[m])
									}
								}

							}
							if (has_oil_code_3 == 0) {
								var countryPrice = ''
								if (this.contry_price_list && this.contry_price_list.length > 0) {
									for (var price of this.contry_price_list) {
										if (price.oil_id == 3) {
											countryPrice = price.oil_price
										}
									}
									if (countryPrice == '') {
										for (var i = 0; i < this.cooperate_oil.length; i++) {
											if (this.cooperate_oil[i] == '0#') {
												this.cooperate_oil.splice(i, 1)
											}
										}
										vant.Toast('0#油品本地没有配置国家价，请联系运营进行配置')
										return
									}
									limit_oils_list.push({
										name: '0#',
										countryPrice: countryPrice,
										stationprice: '',
										oilPrice: '',
										oilDiscount: '',
										settlePrice: '',
										oilgunCode: '',
										oilId: 3
									})
								}


							}
						}
						if (limit_oils[j] == '98#') {
							var has_oil_code_4 = 0
							if (JSON.parse(limit_oils_list_data) && JSON.parse(limit_oils_list_data).length > 0) {
								for (var n = 0; n < JSON.parse(limit_oils_list_data).length; n++) {
									if (JSON.parse(limit_oils_list_data)[n].oilId == 4) {
										limit_oils_list.push(JSON.parse(limit_oils_list_data)[n])
										has_oil_code_4 = 1
									}
								}
							} else if (json_list.oilInfo && json_list.oilInfo.length > 0) {
								for (var m = 0; m < json_list.oilInfo.length; m++) {
									if (json_list.oilInfo[m].oilId == 4) {
										limit_oils_list.push(json_list.oilInfo[m])
										has_oil_code_4 = 1
									}
								}

							}
							if (has_oil_code_4 == 0) {
								var countryPrice = ''
								if (this.contry_price_list && this.contry_price_list.length > 0) {
									for (var price of this.contry_price_list) {
										if (price.oil_id == 4) {
											countryPrice = price.oil_price
										}
									}
									if (countryPrice == '') {
										for (var i = 0; i < this.cooperate_oil.length; i++) {
											if (this.cooperate_oil[i] == '98#') {
												this.cooperate_oil.splice(i, 1)
											}
										}
										vant.Toast('98#油品本地没有配置国家价，请联系运营进行配置')
										return
									}
									limit_oils_list.push({
										name: '98#',
										countryPrice: countryPrice,
										stationprice: '',
										oilPrice: '',
										oilDiscount: '',
										settlePrice: '',
										oilgunCode: '',
										oilId: 4
									})
								}


							}
						}


					}
					// this.$forceUpdate()
					return limit_oils_list
				},
				// 创建工单
				createFormSave: function (json_list_data, fn) {
					var self = this
					var data = {
						order_type_id: this.order_type_id || 1,
						title: self.title,
						content: JSON.stringify(json_list_data),
						remark: '',
						admin_id: this.admin_id,
						work_order_id: this.work_order_id,
						is_exchange: 0
					}
					$.ajax({
						url: '/eapi/v1/activity/work/form_save',
						data: data,
						type: 'post',
						dataType: 'json',
						success: function (res) {
							console.log(res)
							if (res.status == 200) {
								var resData = res.data

								if (fn) {
									fn()
								}
							}
						}
					})
				},
				stationPreferTypeComfirm: function (res) {
					console.log(res)
					this.preferential_type = res
					this.show_prefer_type_picker = false
				},
				selectOilGun: function (oil_gun_item) {
					console.log(oil_gun_item)
					// return
					localStorage.setItem('ejy_cooperate_oil', JSON.stringify(this.cooperate_oil))
					localStorage.setItem('ejy_oilInfo', JSON.stringify(this.oilInfo))

					location.replace('oil_gun.html?look_gd=' + this.look_gd + '&look_gd_text=' + this.look_gd_text +
						'&oil_code_id=' + oil_gun_item.oilId + '&reback_url=' + encodeURIComponent(location.href))
				},
				rebackToLast: function () {
					localStorage.removeItem('ejy_cooperate_oil')
					localStorage.removeItem('ejy_oilInfo')
					location.replace(decodeURIComponent(getQueryVariable('reback_url')))
				},
				saveComeToNext: function () {
					var self = this
					if (this.contry_price_list.length == 0) {
						vant.Toast('请配置好国家价重新填写提交')
						return
					}
					if (this.cooperate_oil.length == 0) {
						vant.Toast('必须选择一个油品')
						return
					}
					json_list.cooperate_oil = this.cooperate_oil
					json_list.oilInfo = this.oilInfo
					// json_list.competitor = this.competitor
					this.createFormSave(json_list, function () {
						localStorage.removeItem('ejy_cooperate_oil')
						localStorage.removeItem('ejy_oilInfo')
						if (json_list.station_race_infomation == 1) {
							location.replace('thired_index.html?look_gd_text=' + this.look_gd_text + '&work_order_id=' + self.work_order_id + '&from_page=' + self.from_page +
								'&admin_id=' + self.admin_id + '&order_type_id=' + self.order_type_id + '&reback_url=' +
								encodeURIComponent(location.href))
						} else {
							location.replace('fourth_index.html?look_gd_text=' + this.look_gd_text + '&work_order_id=' + self.work_order_id + '&from_page=' + self.from_page +
								'&admin_id=' + self.admin_id + '&order_type_id=' + self.order_type_id + '&reback_url=' +
								encodeURIComponent(location.href))

						}
					})

				},
				lookNextStep: function () {
					if (this.cooperate_oil.length == 0) {

					}
					if (json_list.station_race_infomation == 1) {
						location.replace('thired_index.html?look_gd_text=' + this.look_gd_text + '&look_gd=' + this.look_gd +
							'&work_order_id=' + self.work_order_id + '&from_page=' + self.from_page + '&admin_id=' + self.admin_id + '&reback_url=' + encodeURIComponent(
								location.href))
					} else {
						location.replace('fourth_index.html?look_gd_text=' + this.look_gd_text + '&look_gd=' + this.look_gd +
							'&work_order_id=' + self.work_order_id + '&from_page=' + self.from_page + '&admin_id=' + self.admin_id + '&reback_url=' + encodeURIComponent(
								location.href))

					}
				}

			}
		});
		Vue.use(vant.Lazyload);
	</script>
</body>

</html>